﻿using System;
using System.Collections.Generic;

namespace OnePiece.Core.Extension.Paging
{
    public class PageExtensionHelper
    {


        public PageExtensionHelper()
        {
            DefaultPageIndex = 1;
            DefaultPageSize = 20;
        }

        public PageExtensionHelper(int pageIndex, int pageSize, string sortString, string filterString)
            : this()
        {
            PageIndex = pageIndex;
            PageSize = pageSize;
            SortString = sortString;
            LinqFilterString = filterString;
        }


        public int DefaultPageIndex { get; set; }

        public int DefaultPageSize { get; set; }

        private int _pageIndex;
        public int PageIndex
        {
            get { return _pageIndex <= 0 ? DefaultPageIndex : _pageIndex; }
            set { _pageIndex = value; }
        }

        private int _pageSize;
        public int PageSize
        {
            get { return _pageSize <= 0 ? DefaultPageSize : _pageSize; }
            set { _pageSize = value; }
        }
        public string SortString { get; set; }


        public long TotalItems { get; set; }
        public int TotalPages
        {
            get
            {
                return (int)Math.Ceiling(((double)TotalItems) / PageSize);
            }
        }

        public string LinqFilterString { get; set; }

        public virtual PageExtensionHelperFilter Filter { get; set; }

        private IList<object> _filterParameterValue;
        public virtual IList<object> FilterParameterValue
        {
            get
            {
                if (_filterParameterValue == null)
                {
                    _filterParameterValue = new List<object>();
                }
                return _filterParameterValue;
            }
            set
            {
                _filterParameterValue = value;
            }
        }

    }
}
